package org.cpar.compiler.nodes;

import java.util.List;

import org.antlr.runtime.CommonToken;
import org.antlr.runtime.Token;
import org.antlr.runtime.tree.Tree;
import org.cpar.compiler.CPARNode;
import org.cpar.compiler.ICodeWriter;
import org.cpar.compiler.SCPARLexer;

public class SharedObject extends CPARNode {

	private SharedObject(SharedObject o) {
		super(o);
	}

	public SharedObject(Token nextToken) {
		super(nextToken);
	}

	public SharedObject(int shared) {
		this(new CommonToken(SCPARLexer.SHARED));
	}

	@Override
	public void accept(ICodeWriter writer) {
		writer.visit(this);
	}

	@SuppressWarnings("rawtypes")
	public List getNames() {
		return ((CPARNode) getChild(getChildCount() - 1)).getChildren();
	}

	public void setVarType(String type) {
		((CPARNode) ((CPARNode) getChild(getChildCount() - 2)).getChild(0))
				.getToken().setText(type);
	}

	@Override
	public Tree dupNode() {
		return new SharedObject(this);
	}

}
